package com.lehecai.core.api.event;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;


public class PropPropertiesMap {
	
	private static Map<PropType, String[]> propertiesFieldMap = new HashMap<PropType, String[]>();
	private static Map<PropType, String[]> propertiesNameMap = new HashMap<PropType, String[]>();
	private static Map<PropType, String[]> propertiesTypeMap = new HashMap<PropType, String[]>();
	
	static{
		propertiesFieldMap.put(PropType.RECHARGE_DISCOUNT_CARD, new String[]{"recharge_amount","gift_amount"});
		propertiesNameMap.put(PropType.RECHARGE_DISCOUNT_CARD, new String[]{"转换为彩金的现金金额","赠送的彩金金额"});
		propertiesTypeMap.put(PropType.RECHARGE_DISCOUNT_CARD, new String[]{"money","money"});
	}
	
	/**
	 * 根据道具类型获取道具属性
	 * @param propType
	 * @return
	 */
	public static List<PropProperties> getPropPropertiesByType (PropType propType, PropInfo propInfo) {
		if(propType == null){
			return null;
		}
		String[] propertiesFiled = propertiesFieldMap.get(propType);
		String[] propertiesName = propertiesNameMap.get(propType);
		String[] propertiesType = propertiesTypeMap.get(propType);
		if(propertiesFiled == null || propertiesType == null || propertiesName == null){
			return null;
		}
		if (propertiesFiled.length != propertiesType.length || propertiesFiled.length != propertiesName.length ) {
			return null;
		}
		JSONObject obj = null;
		if (propInfo != null) {
			String propertiesStr = propInfo.getProperties();
			obj = JSONObject.fromObject(propertiesStr);
		}
		List<PropProperties> list = new ArrayList<PropProperties>();
		for (int i=0; i<propertiesType.length; i++) {
			PropProperties properties = new PropProperties();
			properties.setField(propertiesFiled[i]);
			properties.setName(propertiesName[i]);
			properties.setType(propertiesType[i]);
			if (obj != null && obj.containsKey(propertiesFiled[i])) {
				properties.setValue(obj.getString(propertiesFiled[i]));
			} else {
				properties.setValue("");
			}
			list.add(properties);
		}
		return list;
	}
	
}

